home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 662 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: changing the size linked to a pointer with keeping the same address
  5. Date: Fri, 05 Jan 1996 17:38:09 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4cjnlc$s0a@news.halcyon.com>
  8. References: <4chia6$1sl@vishnu.jussieu.fr>
  9. NNTP-Posting-Host: blv-pm3-ip9.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. ricou@ann.jussieu.fr (Olivier Ricou) wrote:
  13.  
  14. >Hi,
  15.  
  16. > I want to do a Resize function for my Vector class{int dim, TYPE* elts}. 
  17. >My problem is I can have pointers to elts, so I cannot delete elts and
  18. >make a new one (this would give me an address which has very few chances
  19. >to be the same one than before) or all the pointers to (old) elts will
  20. >point to nothing.
  21.  
  22. > So I would like to have a way to change the size linked to a pointer
  23. >whitout changing the address of the pointer.
  24.  
  25. >                    yours,
  26.  
  27. >                         Olivier.
  28.  
  29. >-- 
  30. >Olivier Ricou                        
  31. >Lab. Analyse Numerique, Paris VI           ricou@ann.jussieu.fr
  32. >tel (1) 44 27 71 70 / 44 07               http://www.ann.jussieu.fr/
  33.  
  34.  
  35. As a rule, I think you're out of luck with the dynamic array appraoch
  36. to the vector.  The realloc() function is guaranteed to keep the same
  37. address if the size of the array shrinks, but not guaranteed to keep
  38. the address if the array grows.  In all cases, realloc() preserves the
  39. contents of the array, even if it has to move it. 
  40.  
  41. Of course, if your vector were implemented as an array of pointers, or
  42. a linked-list, then, obviously, no problem.  Each element will always
  43. point where it initially pointed, but the elements needn't occupy
  44. contiguous memory. 
  45.  
  46. Alternatively, ensure no one aliases that memory.
  47.  
  48. Lastly, under NT, you can reserve virtual memory address space w/o
  49. actually allocating it all.  You can then commit the memory in parcels
  50. as large or small as you like, and the memory will *appear* to your
  51. program as if it were contiguous.  (You can reserve and commit more
  52. than the amount of available RAM this way, too; it appends a range of
  53. the page file to the mapping to make up for the shortage).  
  54.  
  55. Does this help?
  56.                         --Norm
  57.  
  58.